<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - spatial_filtering.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2006  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_SPATIAL_FILTERINg_H_
<font color='#0000FF'>#define</font> DLIB_SPATIAL_FILTERINg_H_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../pixel.h.html'>../pixel.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='spatial_filtering_abstract.h.html'>spatial_filtering_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../assert.h.html'>../assert.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../array2d.h.html'>../array2d.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../geometry/border_enumerator.h.html'>../geometry/border_enumerator.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../simd.h.html'>../simd.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>limits<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> in_image_type,
            <font color='#0000FF'>typename</font> out_image_type,
            <font color='#0000FF'>typename</font> EXP,
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        rectangle <b><a name='grayscale_spatially_filter_image'></a>grayscale_spatially_filter_image</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
            out_image_type<font color='#5555FF'>&amp;</font> out_img,
            <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _filter,
            T scale,
            <font color='#0000FF'><u>bool</u></font> use_abs,
            <font color='#0000FF'><u>bool</u></font> add_to
        <font face='Lucida Console'>)</font>
        <b>{</b>
            const_temp_matrix<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>_filter<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>,
                "<font color='#CC0000'>\trectangle spatially_filter_image()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t You can't give a scale of zero or an empty filter.</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t scale: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> scale
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t filter.nr(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t filter.nc(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
                "<font color='#CC0000'>\trectangle spatially_filter_image()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou must give two different image objects</font>"
            <font face='Lucida Console'>)</font>;



            <font color='#009900'>// if there isn't any input image then don't do anything
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


            <font color='#009900'>// figure out the range that we should apply the filter to
</font>            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_row <font color='#5555FF'>=</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_col <font color='#5555FF'>=</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> rectangle non_border <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>first_col, first_row, last_col<font color='#5555FF'>-</font><font color='#979000'>1</font>, last_row<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>add_to<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>zero_border_pixels</font><font face='Lucida Console'>(</font>out_img, non_border<font face='Lucida Console'>)</font>; 

            <font color='#009900'>// apply the filter to the image
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> first_row; r <font color='#5555FF'>&lt;</font> last_row; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> EXP::type ptype;
                    ptype p;
                    ptype temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#009900'>// pull out the current pixel and put it into p
</font>                            p <font color='#5555FF'>=</font> <font color='#BB00BB'>get_pixel_intensity</font><font face='Lucida Console'>(</font>in_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                            temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>m,n<font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>

                    temp <font color='#5555FF'>/</font><font color='#5555FF'>=</font> scale;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>use_abs <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> temp <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        temp <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp;
                    <b>}</b>

                    <font color='#009900'>// save this pixel to the output image
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp <font color='#5555FF'>+</font> out_img[r][c]<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#0000FF'>return</font> non_border;
        <b>}</b>

    <font color='#009900'>// ------------------------------------------------------------------------------------
</font>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> in_image_type,
            <font color='#0000FF'>typename</font> out_image_type,
            <font color='#0000FF'>typename</font> EXP
            <font color='#5555FF'>&gt;</font>
        rectangle <b><a name='float_spatially_filter_image'></a>float_spatially_filter_image</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
            out_image_type<font color='#5555FF'>&amp;</font> out_img,
            <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _filter,
            <font color='#0000FF'><u>bool</u></font> add_to
        <font face='Lucida Console'>)</font>
        <b>{</b>

            const_temp_matrix<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>_filter<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>,
                "<font color='#CC0000'>\trectangle spatially_filter_image()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t You can't give an empty filter.</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t filter.nr(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t filter.nc(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
                "<font color='#CC0000'>\trectangle spatially_filter_image()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou must give two different image objects</font>"
            <font face='Lucida Console'>)</font>;



            <font color='#009900'>// if there isn't any input image then don't do anything
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


            <font color='#009900'>// figure out the range that we should apply the filter to
</font>            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_row <font color='#5555FF'>=</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_col <font color='#5555FF'>=</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> rectangle non_border <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>first_col, first_row, last_col<font color='#5555FF'>-</font><font color='#979000'>1</font>, last_row<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>add_to<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>zero_border_pixels</font><font face='Lucida Console'>(</font>out_img, non_border<font face='Lucida Console'>)</font>; 

            <font color='#009900'>// apply the filter to the image
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> first_row; r <font color='#5555FF'>&lt;</font> last_row; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> last_col<font color='#5555FF'>-</font><font color='#979000'>7</font>; c<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    simd8f p,p2,p3;
                    simd8f temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>, temp2<font color='#5555FF'>=</font><font color='#979000'>0</font>, temp3<font color='#5555FF'>=</font><font color='#979000'>0</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; n <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font>; n<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#009900'>// pull out the current pixel and put it into p
</font>                            p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                            p2.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n<font color='#5555FF'>+</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                            p3.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n<font color='#5555FF'>+</font><font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
                            temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>m,n<font face='Lucida Console'>)</font>;
                            temp2 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p2<font color='#5555FF'>*</font><font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>m,n<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                            temp3 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p3<font color='#5555FF'>*</font><font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>m,n<font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; n <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#009900'>// pull out the current pixel and put it into p
</font>                            p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                            temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>m,n<font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp2<font color='#5555FF'>+</font>temp3;

                    <font color='#009900'>// save this pixel to the output image
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        temp.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>out_img[r][c]<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>out_img[r][c]<font face='Lucida Console'>)</font>;
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p;
                        temp.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>out_img[r][c]<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'><u>float</u></font> p;
                    <font color='#0000FF'><u>float</u></font> temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#009900'>// pull out the current pixel and put it into p
</font>                            p <font color='#5555FF'>=</font> in_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n];
                            temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>m,n<font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>

                    <font color='#009900'>// save this pixel to the output image
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        out_img[r][c] <font color='#5555FF'>=</font> temp;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        out_img[r][c] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp;
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#0000FF'>return</font> non_border;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>struct</font> <b><a name='is_float_filtering2'></a>is_float_filtering2</b>
    <b>{</b>
        <font color='#0000FF'>const</font> <font color='#0000FF'>static</font> <font color='#0000FF'><u>bool</u></font> value <font color='#5555FF'>=</font> is_same_type<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type,<font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                                  is_same_type<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type,<font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                                  is_same_type<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP::type,<font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::value;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> enable_if_c<font color='#5555FF'>&lt;</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::grayscale <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                         is_float_filtering2<font color='#5555FF'>&lt;</font>in_image_type,out_image_type,EXP<font color='#5555FF'>&gt;</font>::value,rectangle<font color='#5555FF'>&gt;</font>::type 
    <b><a name='spatially_filter_image'></a>spatially_filter_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> filter,
        T scale,
        <font color='#0000FF'><u>bool</u></font> use_abs <font color='#5555FF'>=</font> <font color='#979000'>false</font>,
        <font color='#0000FF'><u>bool</u></font> add_to <font color='#5555FF'>=</font> <font color='#979000'>false</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>use_abs <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> impl::<font color='#BB00BB'>float_spatially_filter_image</font><font face='Lucida Console'>(</font>in_img, out_img, filter, add_to<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#0000FF'>return</font> impl::<font color='#BB00BB'>float_spatially_filter_image</font><font face='Lucida Console'>(</font>in_img, out_img, filter<font color='#5555FF'>/</font>scale, add_to<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>return</font> impl::<font color='#BB00BB'>grayscale_spatially_filter_image</font><font face='Lucida Console'>(</font>in_img, out_img, filter, scale, <font color='#979000'>true</font>, add_to<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> enable_if_c<font color='#5555FF'>&lt;</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::grayscale <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                         <font color='#5555FF'>!</font>is_float_filtering2<font color='#5555FF'>&lt;</font>in_image_type,out_image_type,EXP<font color='#5555FF'>&gt;</font>::value,rectangle<font color='#5555FF'>&gt;</font>::type 
    <b><a name='spatially_filter_image'></a>spatially_filter_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> filter,
        T scale,
        <font color='#0000FF'><u>bool</u></font> use_abs <font color='#5555FF'>=</font> <font color='#979000'>false</font>,
        <font color='#0000FF'><u>bool</u></font> add_to <font color='#5555FF'>=</font> <font color='#979000'>false</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> impl::<font color='#BB00BB'>grayscale_spatially_filter_image</font><font face='Lucida Console'>(</font>in_img,out_img,filter,scale,use_abs,add_to<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> disable_if_c<font color='#5555FF'>&lt;</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::grayscale,rectangle<font color='#5555FF'>&gt;</font>::type 
    <b><a name='spatially_filter_image'></a>spatially_filter_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _filter,
        T scale
    <font face='Lucida Console'>)</font>
    <b>{</b>
        const_temp_matrix<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>_filter<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>,
            "<font color='#CC0000'>\trectangle spatially_filter_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t You can't give a scale of zero or an empty filter.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t scale: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> scale
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t filter.nr(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t filter.nc(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
            "<font color='#CC0000'>\trectangle spatially_filter_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou must give two different image objects</font>"
            <font face='Lucida Console'>)</font>;



        <font color='#009900'>// if there isn't any input image then don't do anything
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        <font color='#009900'>// figure out the range that we should apply the filter to
</font>        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_row <font color='#5555FF'>=</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_col <font color='#5555FF'>=</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rectangle non_border <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>first_col, first_row, last_col<font color='#5555FF'>-</font><font color='#979000'>1</font>, last_row<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>zero_border_pixels</font><font face='Lucida Console'>(</font>out_img, non_border<font face='Lucida Console'>)</font>; 

        <font color='#009900'>// apply the filter to the image
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> first_row; r <font color='#5555FF'>&lt;</font> last_row; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>typedef</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP::type,pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type<font color='#5555FF'>&gt;</font>::num,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> ptype;
                ptype p;
                ptype temp;
                temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> filter.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#009900'>// pull out the current pixel and put it into p
</font>                        p <font color='#5555FF'>=</font> pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP::type<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>in_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>filter</font><font face='Lucida Console'>(</font>m,n<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>

                temp <font color='#5555FF'>/</font><font color='#5555FF'>=</font> scale;

                <font color='#0000FF'>typename</font> in_image_type::type pp;
                <font color='#BB00BB'>vector_to_pixel</font><font face='Lucida Console'>(</font>pp, temp<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], pp<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>return</font> non_border;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP
        <font color='#5555FF'>&gt;</font>
    rectangle <b><a name='spatially_filter_image'></a>spatially_filter_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> filter
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>spatially_filter_image</font><font face='Lucida Console'>(</font>in_img,out_img,filter,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> in_image_type,
            <font color='#0000FF'>typename</font> out_image_type,
            <font color='#0000FF'>typename</font> EXP1,
            <font color='#0000FF'>typename</font> EXP2,
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        rectangle <b><a name='grayscale_spatially_filter_image_separable'></a>grayscale_spatially_filter_image_separable</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
            out_image_type<font color='#5555FF'>&amp;</font> out_img,
            <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _row_filter,
            <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _col_filter,
            T scale,
            <font color='#0000FF'><u>bool</u></font> use_abs,
            <font color='#0000FF'><u>bool</u></font> add_to 
        <font face='Lucida Console'>)</font>
        <b>{</b>
            const_temp_matrix<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>_row_filter<font face='Lucida Console'>)</font>;
            const_temp_matrix<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>_col_filter<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>,
                "<font color='#CC0000'>\trectangle spatially_filter_image_separable()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t scale: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> scale
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t row_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t col_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(row_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font>
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(col_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
                "<font color='#CC0000'>\trectangle spatially_filter_image_separable()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou must give two different image objects</font>"
            <font face='Lucida Console'>)</font>;



            <font color='#009900'>// if there isn't any input image then don't do anything
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


            <font color='#009900'>// figure out the range that we should apply the filter to
</font>            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_row <font color='#5555FF'>=</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_col <font color='#5555FF'>=</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> rectangle non_border <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>first_col, first_row, last_col<font color='#5555FF'>-</font><font color='#979000'>1</font>, last_row<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>add_to<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>zero_border_pixels</font><font face='Lucida Console'>(</font>out_img, non_border<font face='Lucida Console'>)</font>; 

            <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> out_image_type::mem_manager_type mem_manager_type;
            <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> EXP1::type ptype;

            array2d<font color='#5555FF'>&lt;</font>ptype,mem_manager_type<font color='#5555FF'>&gt;</font> temp_img;
            temp_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// apply the row filter
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
                <b>{</b>
                    ptype p;
                    ptype temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#009900'>// pull out the current pixel and put it into p
</font>                        p <font color='#5555FF'>=</font> <font color='#BB00BB'>get_pixel_intensity</font><font face='Lucida Console'>(</font>in_img[r][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    temp_img[r][c] <font color='#5555FF'>=</font> temp;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>// apply the column filter 
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> first_row; r <font color='#5555FF'>&lt;</font> last_row; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
                <b>{</b>
                    ptype temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                    <b>{</b>
                        temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c]<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
                    <b>}</b>

                    temp <font color='#5555FF'>/</font><font color='#5555FF'>=</font> scale;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>use_abs <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> temp <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        temp <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp;
                    <b>}</b>

                    <font color='#009900'>// save this pixel to the output image
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp <font color='#5555FF'>+</font> out_img[r][c]<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>return</font> non_border;
        <b>}</b>

    <b>}</b> <font color='#009900'>// namespace impl
</font>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>struct</font> <b><a name='is_float_filtering'></a>is_float_filtering</b>
    <b>{</b>
        <font color='#0000FF'>const</font> <font color='#0000FF'>static</font> <font color='#0000FF'><u>bool</u></font> value <font color='#5555FF'>=</font> is_same_type<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type,<font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                                  is_same_type<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type,<font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                                  is_same_type<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP1::type,<font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                                  is_same_type<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP2::type,<font color='#0000FF'><u>float</u></font><font color='#5555FF'>&gt;</font>::value;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#009900'>// This overload is optimized to use SIMD instructions when filtering float images with
</font>    <font color='#009900'>// float filters.
</font>    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2
        <font color='#5555FF'>&gt;</font>
    rectangle <b><a name='float_spatially_filter_image_separable'></a>float_spatially_filter_image_separable</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _row_filter,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _col_filter,
        out_image_type<font color='#5555FF'>&amp;</font> scratch,
        <font color='#0000FF'><u>bool</u></font> add_to <font color='#5555FF'>=</font> <font color='#979000'>false</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// You can only use this function with images and filters containing float
</font>        <font color='#009900'>// variables.
</font>        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>is_float_filtering<font color='#5555FF'>&lt;</font>in_image_type,out_image_type,EXP1,EXP2<font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        const_temp_matrix<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>_row_filter<font face='Lucida Console'>)</font>;
        const_temp_matrix<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>_col_filter<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\trectangle float_spatially_filter_image_separable()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t row_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t col_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(row_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(col_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
            "<font color='#CC0000'>\trectangle float_spatially_filter_image_separable()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou must give two different image objects</font>"
        <font face='Lucida Console'>)</font>;



        <font color='#009900'>// if there isn't any input image then don't do anything
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// figure out the range that we should apply the filter to
</font>        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_row <font color='#5555FF'>=</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_col <font color='#5555FF'>=</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rectangle non_border <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>first_col, first_row, last_col<font color='#5555FF'>-</font><font color='#979000'>1</font>, last_row<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>add_to<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>zero_border_pixels</font><font face='Lucida Console'>(</font>out_img, non_border<font face='Lucida Console'>)</font>; 

        scratch.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// apply the row filter
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> last_col<font color='#5555FF'>-</font><font color='#979000'>7</font>; c<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>
            <b>{</b>
                simd8f p,p2,p3, temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>, temp2<font color='#5555FF'>=</font><font color='#979000'>0</font>, temp3<font color='#5555FF'>=</font><font color='#979000'>0</font>;
                <font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; n <font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font>; n<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// pull out the current pixel and put it into p
</font>                    p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                    p2.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n<font color='#5555FF'>+</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                    p3.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n<font color='#5555FF'>+</font><font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>;
                    temp2 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p2<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    temp3 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p3<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; n <font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// pull out the current pixel and put it into p
</font>                    p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>in_img[r][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>;
                <b>}</b>
                temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp2 <font color='#5555FF'>+</font> temp3;
                temp.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>scratch[r][c]<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>float</u></font> p;
                <font color='#0000FF'><u>float</u></font> temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// pull out the current pixel and put it into p
</font>                    p <font color='#5555FF'>=</font> in_img[r][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n];
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>;
                <b>}</b>
                scratch[r][c] <font color='#5555FF'>=</font> temp;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// apply the column filter 
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> first_row; r <font color='#5555FF'>&lt;</font> last_row; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> last_col<font color='#5555FF'>-</font><font color='#979000'>7</font>; c<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>
            <b>{</b>
                simd8f p, p2, p3, temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>, temp2 <font color='#5555FF'>=</font> <font color='#979000'>0</font>, temp3 <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; m <font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>2</font>; m<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>scratch[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c]<font face='Lucida Console'>)</font>;
                    p2.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>scratch[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m<font color='#5555FF'>+</font><font color='#979000'>1</font>][c]<font face='Lucida Console'>)</font>;
                    p3.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>scratch[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m<font color='#5555FF'>+</font><font color='#979000'>2</font>][c]<font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
                    temp2 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p2<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    temp3 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p3<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font color='#5555FF'>+</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; m <font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                <b>{</b>
                    p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>scratch[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c]<font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
                <b>}</b>
                temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp2<font color='#5555FF'>+</font>temp3;

                <font color='#009900'>// save this pixel to the output image
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    temp.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>out_img[r][c]<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    p.<font color='#BB00BB'>load</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>out_img[r][c]<font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p;
                    temp.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>out_img[r][c]<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>float</u></font> temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                <b>{</b>
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> scratch[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c]<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#009900'>// save this pixel to the output image
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    out_img[r][c] <font color='#5555FF'>=</font> temp;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    out_img[r][c] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp;
                <b>}</b>
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>return</font> non_border;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> enable_if_c<font color='#5555FF'>&lt;</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::grayscale <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                         is_float_filtering<font color='#5555FF'>&lt;</font>in_image_type,out_image_type,EXP1,EXP2<font color='#5555FF'>&gt;</font>::value,rectangle<font color='#5555FF'>&gt;</font>::type 
    <b><a name='spatially_filter_image_separable'></a>spatially_filter_image_separable</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> row_filter,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> col_filter,
        T scale,
        <font color='#0000FF'><u>bool</u></font> use_abs <font color='#5555FF'>=</font> <font color='#979000'>false</font>,
        <font color='#0000FF'><u>bool</u></font> add_to <font color='#5555FF'>=</font> <font color='#979000'>false</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>use_abs <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            out_image_type scratch;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#BB00BB'>float_spatially_filter_image_separable</font><font face='Lucida Console'>(</font>in_img, out_img, row_filter, col_filter, scratch, add_to<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#0000FF'>return</font> <font color='#BB00BB'>float_spatially_filter_image_separable</font><font face='Lucida Console'>(</font>in_img, out_img, row_filter<font color='#5555FF'>/</font>scale, col_filter, scratch,  add_to<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>return</font> impl::<font color='#BB00BB'>grayscale_spatially_filter_image_separable</font><font face='Lucida Console'>(</font>in_img, out_img, row_filter, col_filter, scale, <font color='#979000'>true</font>, add_to<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> enable_if_c<font color='#5555FF'>&lt;</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::grayscale <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                         <font color='#5555FF'>!</font>is_float_filtering<font color='#5555FF'>&lt;</font>in_image_type,out_image_type,EXP1,EXP2<font color='#5555FF'>&gt;</font>::value,rectangle<font color='#5555FF'>&gt;</font>::type 
    <b><a name='spatially_filter_image_separable'></a>spatially_filter_image_separable</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> row_filter,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> col_filter,
        T scale,
        <font color='#0000FF'><u>bool</u></font> use_abs <font color='#5555FF'>=</font> <font color='#979000'>false</font>,
        <font color='#0000FF'><u>bool</u></font> add_to <font color='#5555FF'>=</font> <font color='#979000'>false</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> impl::<font color='#BB00BB'>grayscale_spatially_filter_image_separable</font><font face='Lucida Console'>(</font>in_img,out_img, row_filter, col_filter, scale, use_abs, add_to<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> disable_if_c<font color='#5555FF'>&lt;</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::grayscale,rectangle<font color='#5555FF'>&gt;</font>::type 
    <b><a name='spatially_filter_image_separable'></a>spatially_filter_image_separable</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _row_filter,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> _col_filter,
        T scale
    <font face='Lucida Console'>)</font>
    <b>{</b>
        const_temp_matrix<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>_row_filter<font face='Lucida Console'>)</font>;
        const_temp_matrix<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>_col_filter<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\trectangle spatially_filter_image_separable()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t scale: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> scale
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t row_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t col_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(row_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(col_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
            "<font color='#CC0000'>\trectangle spatially_filter_image_separable()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou must give two different image objects</font>"
            <font face='Lucida Console'>)</font>;



        <font color='#009900'>// if there isn't any input image then don't do anything
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


        <font color='#009900'>// figure out the range that we should apply the filter to
</font>        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_row <font color='#5555FF'>=</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_col <font color='#5555FF'>=</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col <font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rectangle non_border <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>first_col, first_row, last_col<font color='#5555FF'>-</font><font color='#979000'>1</font>, last_row<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>zero_border_pixels</font><font face='Lucida Console'>(</font>out_img, non_border<font face='Lucida Console'>)</font>; 

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> out_image_type::mem_manager_type mem_manager_type;
        <font color='#0000FF'>typedef</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP1::type,pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type<font color='#5555FF'>&gt;</font>::num,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> ptype;

        array2d<font color='#5555FF'>&lt;</font>ptype,mem_manager_type<font color='#5555FF'>&gt;</font> temp_img;
        temp_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// apply the row filter
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                ptype p;
                ptype temp;
                temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// pull out the current pixel and put it into p
</font>                    p <font color='#5555FF'>=</font> pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> EXP1::type<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>in_img[r][c<font color='#5555FF'>-</font>first_col<font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>;
                <b>}</b>
                temp_img[r][c] <font color='#5555FF'>=</font> temp;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// apply the column filter 
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> first_row; r <font color='#5555FF'>&lt;</font> last_row; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> first_col; c <font color='#5555FF'>&lt;</font> last_col; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                ptype temp;
                temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                <b>{</b>
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp_img[r<font color='#5555FF'>-</font>first_row<font color='#5555FF'>+</font>m][c]<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
                <b>}</b>

                temp <font color='#5555FF'>/</font><font color='#5555FF'>=</font> scale;


                <font color='#009900'>// save this pixel to the output image
</font>                <font color='#0000FF'>typename</font> in_image_type::type p;
                <font color='#BB00BB'>vector_to_pixel</font><font face='Lucida Console'>(</font>p, temp<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], p<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>return</font> non_border;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2
        <font color='#5555FF'>&gt;</font>
    rectangle <b><a name='spatially_filter_image_separable'></a>spatially_filter_image_separable</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> row_filter,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> col_filter
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>spatially_filter_image_separable</font><font face='Lucida Console'>(</font>in_img,out_img,row_filter,col_filter,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    rectangle <b><a name='spatially_filter_image_separable_down'></a>spatially_filter_image_separable_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> downsample,
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> row_filter,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> col_filter,
        T scale,
        <font color='#0000FF'><u>bool</u></font> use_abs <font color='#5555FF'>=</font> <font color='#979000'>false</font>,
        <font color='#0000FF'><u>bool</u></font> add_to <font color='#5555FF'>=</font> <font color='#979000'>false</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> in_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::grayscale <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font> <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>downsample <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>%</font><font color='#979000'>2</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>%</font><font color='#979000'>2</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\trectangle spatially_filter_image_separable_down()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t downsample: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> downsample
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t scale: </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> scale
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t row_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t col_filter.size(): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(row_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>row_filter<font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(col_filter): </font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>col_filter<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
            "<font color='#CC0000'>\trectangle spatially_filter_image_separable_down()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tYou must give two different image objects</font>"
            <font face='Lucida Console'>)</font>;



        <font color='#009900'>// if there isn't any input image then don't do anything
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>ceil</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>downsample<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
                         <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>ceil</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>downsample<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> col_border <font color='#5555FF'>=</font> std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> row_border <font color='#5555FF'>=</font> std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2.0</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// figure out the range that we should apply the filter to
</font>        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_row <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>ceil</font><font face='Lucida Console'>(</font>col_border<font color='#5555FF'>/</font>downsample<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> first_col <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>ceil</font><font face='Lucida Console'>(</font>row_border<font color='#5555FF'>/</font>downsample<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row  <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>ceil</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> col_border<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>downsample<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col  <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>ceil</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> row_border<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>downsample<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;

        <font color='#009900'>// zero border pixels
</font>        <font color='#0000FF'>const</font> rectangle non_border <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>first_col, first_row, last_col, last_row<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>zero_border_pixels</font><font face='Lucida Console'>(</font>out_img,non_border<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> EXP1::type ptype;

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> out_image_type::mem_manager_type mem_manager_type;
        array2d<font color='#5555FF'>&lt;</font>ptype,mem_manager_type<font color='#5555FF'>&gt;</font> temp_img;
        temp_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// apply the row filter
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> temp_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> non_border.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; c <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> non_border.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                ptype p;
                ptype temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// pull out the current pixel and put it into p
</font>                    p <font color='#5555FF'>=</font> <font color='#BB00BB'>get_pixel_intensity</font><font face='Lucida Console'>(</font>in_img[r][c<font color='#5555FF'>*</font>downsample<font color='#5555FF'>-</font>row_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font>n]<font face='Lucida Console'>)</font>;
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> p<font color='#5555FF'>*</font><font color='#BB00BB'>row_filter</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>;
                <b>}</b>
                temp_img[r][c] <font color='#5555FF'>=</font> temp;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// apply the column filter 
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> non_border.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; r <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> non_border.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> non_border.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; c <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> non_border.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                ptype temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> m <font color='#5555FF'>=</font> <font color='#979000'>0</font>; m <font color='#5555FF'>&lt;</font> col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>m<font face='Lucida Console'>)</font>
                <b>{</b>
                    temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> temp_img[r<font color='#5555FF'>*</font>downsample<font color='#5555FF'>-</font>col_filter.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font>m][c]<font color='#5555FF'>*</font><font color='#BB00BB'>col_filter</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
                <b>}</b>

                temp <font color='#5555FF'>/</font><font color='#5555FF'>=</font> scale;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>use_abs <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> temp <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    temp <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>temp;
                <b>}</b>

                <font color='#009900'>// save this pixel to the output image
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp <font color='#5555FF'>+</font> out_img[r][c]<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>return</font> non_border;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type,
        <font color='#0000FF'>typename</font> EXP1,
        <font color='#0000FF'>typename</font> EXP2
        <font color='#5555FF'>&gt;</font>
    rectangle <b><a name='spatially_filter_image_separable_down'></a>spatially_filter_image_separable_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> downsample,
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP1<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> row_filter,
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> col_filter
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> <font color='#BB00BB'>spatially_filter_image_separable_down</font><font face='Lucida Console'>(</font>downsample,in_img,out_img,row_filter,col_filter,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'><u>long</u></font> NR,
        <font color='#0000FF'><u>long</u></font> NC,
        <font color='#0000FF'>typename</font> T,
        <font color='#0000FF'>typename</font> U,
        <font color='#0000FF'>typename</font> in_image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='separable_3x3_filter_block_grayscale'></a>separable_3x3_filter_block_grayscale</b> <font face='Lucida Console'>(</font>
        <font color='#BB00BB'>T</font> <font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>block<font face='Lucida Console'>)</font>[NR][NC],
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> r,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> c,
        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> fe1, <font color='#009900'>// separable filter end
</font>        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> fm,  <font color='#009900'>// separable filter middle 
</font>        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> fe2 <font color='#009900'>// separable filter end 2
</font>    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>c,r<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>c<font color='#5555FF'>+</font>NC<font color='#5555FF'>-</font><font color='#979000'>1</font>,r<font color='#5555FF'>+</font>NR<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void separable_3x3_filter_block_grayscale()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t The sub-window doesn't fit inside the given image.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t get_rect(img):       </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t (c,r):               </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>c,r<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t (c+NC-1,r+NR-1): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>c<font color='#5555FF'>+</font>NC<font color='#5555FF'>-</font><font color='#979000'>1</font>,r<font color='#5555FF'>+</font>NR<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;


        T row_filt[NR<font color='#5555FF'>+</font><font color='#979000'>2</font>][NC];
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> rr <font color='#5555FF'>=</font> <font color='#979000'>0</font>; rr <font color='#5555FF'>&lt;</font> NR<font color='#5555FF'>+</font><font color='#979000'>2</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>rr<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> cc <font color='#5555FF'>=</font> <font color='#979000'>0</font>; cc <font color='#5555FF'>&lt;</font> NC; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>cc<font face='Lucida Console'>)</font>
            <b>{</b>
                row_filt[rr][cc] <font color='#5555FF'>=</font> <font color='#BB00BB'>get_pixel_intensity</font><font face='Lucida Console'>(</font>img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>fe1 <font color='#5555FF'>+</font> 
                                   <font color='#BB00BB'>get_pixel_intensity</font><font face='Lucida Console'>(</font>img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc]<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>fm <font color='#5555FF'>+</font> 
                                   <font color='#BB00BB'>get_pixel_intensity</font><font face='Lucida Console'>(</font>img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>+</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>fe2;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> rr <font color='#5555FF'>=</font> <font color='#979000'>0</font>; rr <font color='#5555FF'>&lt;</font> NR; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>rr<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> cc <font color='#5555FF'>=</font> <font color='#979000'>0</font>; cc <font color='#5555FF'>&lt;</font> NC; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>cc<font face='Lucida Console'>)</font>
            <b>{</b>
                block[rr][cc] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>row_filt[rr][cc]<font color='#5555FF'>*</font>fe1 <font color='#5555FF'>+</font> 
                                row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>1</font>][cc]<font color='#5555FF'>*</font>fm <font color='#5555FF'>+</font> 
                                row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>2</font>][cc]<font color='#5555FF'>*</font>fe2<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'><u>long</u></font> NR,
        <font color='#0000FF'><u>long</u></font> NC,
        <font color='#0000FF'>typename</font> T,
        <font color='#0000FF'>typename</font> U,
        <font color='#0000FF'>typename</font> in_image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='separable_3x3_filter_block_rgb'></a>separable_3x3_filter_block_rgb</b> <font face='Lucida Console'>(</font>
        <font color='#BB00BB'>T</font> <font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>block<font face='Lucida Console'>)</font>[NR][NC],
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> r,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> c,
        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> fe1, <font color='#009900'>// separable filter end
</font>        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> fm,  <font color='#009900'>// separable filter middle 
</font>        <font color='#0000FF'>const</font> U<font color='#5555FF'>&amp;</font> fe2  <font color='#009900'>// separable filter end 2
</font>    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>c,r<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>c<font color='#5555FF'>+</font>NC<font color='#5555FF'>-</font><font color='#979000'>1</font>,r<font color='#5555FF'>+</font>NR<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void separable_3x3_filter_block_rgb()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t The sub-window doesn't fit inside the given image.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t get_rect(img):       </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t (c,r):               </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>c,r<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t (c+NC-1,r+NR-1): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>c<font color='#5555FF'>+</font>NC<font color='#5555FF'>-</font><font color='#979000'>1</font>,r<font color='#5555FF'>+</font>NR<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        T row_filt[NR<font color='#5555FF'>+</font><font color='#979000'>2</font>][NC];
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> rr <font color='#5555FF'>=</font> <font color='#979000'>0</font>; rr <font color='#5555FF'>&lt;</font> NR<font color='#5555FF'>+</font><font color='#979000'>2</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>rr<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> cc <font color='#5555FF'>=</font> <font color='#979000'>0</font>; cc <font color='#5555FF'>&lt;</font> NC; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>cc<font face='Lucida Console'>)</font>
            <b>{</b>
                row_filt[rr][cc].red   <font color='#5555FF'>=</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>-</font><font color='#979000'>1</font>].red<font color='#5555FF'>*</font>fe1   <font color='#5555FF'>+</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc].red<font color='#5555FF'>*</font>fm   <font color='#5555FF'>+</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>+</font><font color='#979000'>1</font>].red<font color='#5555FF'>*</font>fe2;
                row_filt[rr][cc].green <font color='#5555FF'>=</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>-</font><font color='#979000'>1</font>].green<font color='#5555FF'>*</font>fe1 <font color='#5555FF'>+</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc].green<font color='#5555FF'>*</font>fm <font color='#5555FF'>+</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>+</font><font color='#979000'>1</font>].green<font color='#5555FF'>*</font>fe2;
                row_filt[rr][cc].blue  <font color='#5555FF'>=</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>-</font><font color='#979000'>1</font>].blue<font color='#5555FF'>*</font>fe1  <font color='#5555FF'>+</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc].blue<font color='#5555FF'>*</font>fm  <font color='#5555FF'>+</font> img[r<font color='#5555FF'>+</font>rr<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font>cc<font color='#5555FF'>+</font><font color='#979000'>1</font>].blue<font color='#5555FF'>*</font>fe2;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> rr <font color='#5555FF'>=</font> <font color='#979000'>0</font>; rr <font color='#5555FF'>&lt;</font> NR; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>rr<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> cc <font color='#5555FF'>=</font> <font color='#979000'>0</font>; cc <font color='#5555FF'>&lt;</font> NC; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>cc<font face='Lucida Console'>)</font>
            <b>{</b>
                block[rr][cc].red   <font color='#5555FF'>=</font> row_filt[rr][cc].red<font color='#5555FF'>*</font>fe1   <font color='#5555FF'>+</font> row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>1</font>][cc].red<font color='#5555FF'>*</font>fm   <font color='#5555FF'>+</font> row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>2</font>][cc].red<font color='#5555FF'>*</font>fe2;
                block[rr][cc].green <font color='#5555FF'>=</font> row_filt[rr][cc].green<font color='#5555FF'>*</font>fe1 <font color='#5555FF'>+</font> row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>1</font>][cc].green<font color='#5555FF'>*</font>fm <font color='#5555FF'>+</font> row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>2</font>][cc].green<font color='#5555FF'>*</font>fe2;
                block[rr][cc].blue  <font color='#5555FF'>=</font> row_filt[rr][cc].blue<font color='#5555FF'>*</font>fe1  <font color='#5555FF'>+</font> row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>1</font>][cc].blue<font color='#5555FF'>*</font>fm  <font color='#5555FF'>+</font> row_filt[rr<font color='#5555FF'>+</font><font color='#979000'>2</font>][cc].blue<font color='#5555FF'>*</font>fe2;
            <b>}</b>
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>double</u></font> <b><a name='gaussian'></a>gaussian</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> x, 
        <font color='#0000FF'><u>double</u></font> sigma
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>sigma <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font>,
            "<font color='#CC0000'>\tdouble gaussian(x)</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t sigma must be bigger than 0</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t sigma: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> sigma 
        <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> sqrt_2_pi <font color='#5555FF'>=</font> <font color='#979000'>2.5066282746310002416123552393401041626930</font>;
        <font color='#0000FF'>return</font> <font color='#979000'>1.0</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font>sigma<font color='#5555FF'>*</font>sqrt_2_pi<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> std::<font color='#BB00BB'>exp</font><font face='Lucida Console'>(</font> <font color='#5555FF'>-</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>*</font>x<font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font color='#5555FF'>*</font>sigma<font color='#5555FF'>*</font>sigma<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    matrix<font color='#5555FF'>&lt;</font>T,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <b><a name='create_gaussian_filter'></a>create_gaussian_filter</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> sigma,
        <font color='#0000FF'><u>int</u></font> max_size 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>sigma <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> max_size <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>max_size<font color='#5555FF'>%</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>1</font>,
            "<font color='#CC0000'>\t matrix&lt;T,0,1&gt; create_gaussian_filter()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t sigma: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> sigma 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t max_size:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> max_size 
        <font face='Lucida Console'>)</font>;

        <font color='#009900'>// Adjust the size so that the ratio of the gaussian values isn't huge.  
</font>        <font color='#009900'>// This only matters when T is an integer type.  However, we do it for
</font>        <font color='#009900'>// all types so that the behavior of this function is always relatively
</font>        <font color='#009900'>// the same.
</font>        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>gaussian</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,sigma<font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#BB00BB'>gaussian</font><font face='Lucida Console'>(</font>max_size<font color='#5555FF'>/</font><font color='#979000'>2</font>,sigma<font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>50</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>-</font><font color='#5555FF'>-</font>max_size;


        matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font>max_size<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> f.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>gaussian</font><font face='Lucida Console'>(</font>i<font color='#5555FF'>-</font>max_size<font color='#5555FF'>/</font><font color='#979000'>2</font>, sigma<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_float_type<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font>::value <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            f <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#BB00BB'>f</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> matrix_cast<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>return</font> matrix_cast<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> in_image_type,
        <font color='#0000FF'>typename</font> out_image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='gaussian_blur'></a>gaussian_blur</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> in_image_type<font color='#5555FF'>&amp;</font> in_img,
        out_image_type<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'><u>double</u></font> sigma <font color='#5555FF'>=</font> <font color='#979000'>1</font>,
        <font color='#0000FF'><u>int</u></font> max_size <font color='#5555FF'>=</font> <font color='#979000'>1001</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>sigma <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> max_size <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>max_size<font color='#5555FF'>%</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>1</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
            "<font color='#CC0000'>\t void gaussian_blur()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t sigma: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> sigma 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t max_size:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> max_size 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img,out_img): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img,out_img<font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> out_image_type::type<font color='#5555FF'>&gt;</font>::basic_pixel_type type;
        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> promote<font color='#5555FF'>&lt;</font>type<font color='#5555FF'>&gt;</font>::type ptype;

        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font>ptype,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> filt <font color='#5555FF'>=</font> create_gaussian_filter<font color='#5555FF'>&lt;</font>ptype<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>sigma, max_size<font face='Lucida Console'>)</font>;

        ptype scale <font color='#5555FF'>=</font> <font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>filt<font face='Lucida Console'>)</font>;
        scale <font color='#5555FF'>=</font> scale<font color='#5555FF'>*</font>scale;

        <font color='#BB00BB'>spatially_filter_image_separable</font><font face='Lucida Console'>(</font>in_img, out_img, filt, filt, scale<font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'><u>bool</u></font> add_to,
        <font color='#0000FF'>typename</font> image_type1, 
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='sum_filter'></a>sum_filter</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> img,
        image_type2<font color='#5555FF'>&amp;</font> out,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> out.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> out.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                    <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>img,out<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
            "<font color='#CC0000'>\t void sum_filter()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid arguments given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t img.nr(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t img.nc(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t out.nr(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> out.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t out.nc(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> out.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(img,out): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>img,out<font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> image_type1::type pixel_type;
        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> promote<font color='#5555FF'>&lt;</font>pixel_type<font color='#5555FF'>&gt;</font>::type ptype;

        std::vector<font color='#5555FF'>&lt;</font>ptype<font color='#5555FF'>&gt;</font> column_sum;
        column_sum.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>long</u></font> left <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>;

        <font color='#009900'>// initialize column_sum at row -1
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> column_sum.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
        <b>{</b>
            rectangle <font color='#BB00BB'>strip</font><font face='Lucida Console'>(</font>left,top,left,bottom<font face='Lucida Console'>)</font>;
            strip <font color='#5555FF'>=</font> strip.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>strip.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                column_sum[j] <font color='#5555FF'>=</font> <font color='#BB00BB'>sum</font><font face='Lucida Console'>(</font>matrix_cast<font color='#5555FF'>&lt;</font>ptype<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>subm</font><font face='Lucida Console'>(</font><font color='#BB00BB'>mat</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>,strip<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#5555FF'>+</font><font color='#5555FF'>+</font>left;
        <b>}</b>


        <font color='#0000FF'>const</font> rectangle area <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;

        <font color='#009900'>// Save width to avoid computing it over and over.
</font>        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> width <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;


        <font color='#009900'>// Now do the bulk of the filtering work.
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// set to sum at point(-1,r). i.e. should be equal to sum(mat(img), translate_rect(rect, point(-1,r)))
</font>            <font color='#009900'>// We compute it's value in the next loop.
</font>            ptype cur_sum <font color='#5555FF'>=</font> <font color='#979000'>0</font>; 

            <font color='#009900'>// Update the first part of column_sum since we only work on the c+width part of column_sum
</font>            <font color='#009900'>// in the main loop.
</font>            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> r <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> r <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> <font color='#979000'>0</font>; k <font color='#5555FF'>&lt;</font> width; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> k<font color='#5555FF'>-</font>width <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>const</font> ptype br_corner <font color='#5555FF'>=</font> area.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>right,bottom<font face='Lucida Console'>)</font> ? img[bottom][right] : <font color='#979000'>0</font>;
                <font color='#0000FF'>const</font> ptype tr_corner <font color='#5555FF'>=</font> area.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>right,top<font face='Lucida Console'>)</font>    ? img[top][right]    : <font color='#979000'>0</font>;
                <font color='#009900'>// update the sum in this column now that we are on the next row
</font>                column_sum[k] <font color='#5555FF'>=</font> column_sum[k] <font color='#5555FF'>+</font> br_corner <font color='#5555FF'>-</font> tr_corner;
                cur_sum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> column_sum[k];
            <b>}</b>

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> r <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> r <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> c <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                <font color='#0000FF'>const</font> ptype br_corner <font color='#5555FF'>=</font> area.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>right,bottom<font face='Lucida Console'>)</font> ? img[bottom][right] : <font color='#979000'>0</font>;
                <font color='#0000FF'>const</font> ptype tr_corner <font color='#5555FF'>=</font> area.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>right,top<font face='Lucida Console'>)</font>    ? img[top][right]    : <font color='#979000'>0</font>;

                <font color='#009900'>// update the sum in this column now that we are on the next row
</font>                column_sum[c<font color='#5555FF'>+</font>width] <font color='#5555FF'>=</font> column_sum[c<font color='#5555FF'>+</font>width] <font color='#5555FF'>+</font> br_corner <font color='#5555FF'>-</font> tr_corner;

                <font color='#009900'>// add in the new right side of the rect and subtract the old right side.
</font>                cur_sum <font color='#5555FF'>=</font> cur_sum <font color='#5555FF'>+</font> column_sum[c<font color='#5555FF'>+</font>width] <font color='#5555FF'>-</font> column_sum[c];

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>add_to<font face='Lucida Console'>)</font>
                    out[r][c] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type2::type<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>cur_sum<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font>
                    out[r][c] <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type2::type<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>cur_sum<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1, 
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='sum_filter'></a>sum_filter</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> img,
        image_type2<font color='#5555FF'>&amp;</font> out,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
    <font face='Lucida Console'>)</font>
    <b>{</b>
        impl::sum_filter<font color='#5555FF'>&lt;</font><font color='#979000'>true</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>img,out,rect<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1, 
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='sum_filter_assign'></a>sum_filter_assign</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> img,
        image_type2<font color='#5555FF'>&amp;</font> out,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
    <font face='Lucida Console'>)</font>
    <b>{</b>
        out.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        impl::sum_filter<font color='#5555FF'>&lt;</font><font color='#979000'>false</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>img,out,rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>class</font> <b><a name='fast_deque'></a>fast_deque</b>
        <b>{</b>
        <font color='#009900'>/*
            This is a fast and minimal implementation of std::deque for 
            use with the max_filter.  

            This object assumes that no more than max_size elements
            will ever be pushed into it at a time.
        */</font>
        <font color='#0000FF'>public</font>:

            <font color='#0000FF'>explicit</font> <b><a name='fast_deque'></a>fast_deque</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> max_size<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// find a power of two that upper bounds max_size
</font>                mask <font color='#5555FF'>=</font> <font color='#979000'>2</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>mask <font color='#5555FF'>&lt;</font> max_size<font face='Lucida Console'>)</font>
                    mask <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;

                <font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                data.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>mask<font face='Lucida Console'>)</font>;
                <font color='#5555FF'>-</font><font color='#5555FF'>-</font>mask;  <font color='#009900'>// make into bit mask
</font>            <b>}</b>

            <font color='#0000FF'><u>void</u></font> <b><a name='clear'></a>clear</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <b>{</b>
                first <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
                last <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
                size <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <b>}</b>

            <font color='#0000FF'><u>bool</u></font> <b><a name='empty'></a>empty</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>return</font> size <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <b>}</b>

            <font color='#0000FF'><u>void</u></font> <b><a name='pop_back'></a>pop_back</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <b>{</b>
                last <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>last<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>&amp;</font>mask;
                <font color='#5555FF'>-</font><font color='#5555FF'>-</font>size;
            <b>}</b>

            <font color='#0000FF'><u>void</u></font> <b><a name='push_back'></a>push_back</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> T<font color='#5555FF'>&amp;</font> item<font face='Lucida Console'>)</font>
            <b>{</b>
                last <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>last<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>&amp;</font>mask;
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>size;
                data[last] <font color='#5555FF'>=</font> item;
            <b>}</b>

            <font color='#0000FF'><u>void</u></font> <b><a name='pop_front'></a>pop_front</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <b>{</b>
                first <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>first<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>&amp;</font>mask;
                <font color='#5555FF'>-</font><font color='#5555FF'>-</font>size;
            <b>}</b>

            <font color='#0000FF'>const</font> T<font color='#5555FF'>&amp;</font> <b><a name='front'></a>front</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>return</font> data[first];
            <b>}</b>

            <font color='#0000FF'>const</font> T<font color='#5555FF'>&amp;</font> <b><a name='back'></a>back</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>return</font> data[last];
            <b>}</b>

        <font color='#0000FF'>private</font>:

            std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> data;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> mask;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> first;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> last;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> size;
        <b>}</b>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1, 
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='max_filter'></a>max_filter</b> <font face='Lucida Console'>(</font>
        image_type1<font color='#5555FF'>&amp;</font> img,
        image_type2<font color='#5555FF'>&amp;</font> out,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> height,
        <font color='#0000FF'>const</font> <font color='#0000FF'>typename</font> image_type1::type<font color='#5555FF'>&amp;</font> thresh
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> width <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     height <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     out.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     out.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>img,out<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
                "<font color='#CC0000'>\t void max_filter()</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid arguments given to this function.</font>"
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t img.nr(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t img.nc(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t out.nr(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> out.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t out.nc(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> out.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t width:    </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> width 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t height:   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> height 
                <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(img,out): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>img,out<font face='Lucida Console'>)</font> 
                     <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> image_type1::type pixel_type;


        dlib::impl::fast_deque<font color='#5555FF'>&lt;</font>std::pair<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font>,pixel_type<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <font color='#BB00BB'>Q</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_col <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> last_row <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// run max filter along rows of img
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            Q.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> c <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> img[r][c] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> Q.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                Q.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>c,img[r][c]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>; c <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> img[r][c] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> Q.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.first <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> c<font color='#5555FF'>-</font>width<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                Q.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>c,img[r][c]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                img[r][c<font color='#5555FF'>-</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second;
            <b>}</b>

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> last_col; c <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.first <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> c<font color='#5555FF'>-</font>width<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                img[r][c<font color='#5555FF'>-</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>] <font color='#5555FF'>=</font> Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// run max filter along columns of img.  Store result in out.
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> cc <font color='#5555FF'>=</font> <font color='#979000'>0</font>; cc <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>cc<font face='Lucida Console'>)</font>
        <b>{</b>
            Q.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> rr <font color='#5555FF'>=</font> <font color='#979000'>0</font>; rr <font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rr <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>rr<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> img[rr][cc] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> Q.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                Q.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>rr,img[rr][cc]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> rr <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>; rr <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>rr<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> img[rr][cc] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> Q.<font color='#BB00BB'>back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_back</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.first <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> rr<font color='#5555FF'>-</font>height<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                Q.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>make_pair</font><font face='Lucida Console'>(</font>rr,img[rr][cc]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                out[rr<font color='#5555FF'>-</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>][cc] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second, thresh<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> rr <font color='#5555FF'>=</font> last_row; rr <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>rr<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>Q.<font color='#BB00BB'>empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.first <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> rr<font color='#5555FF'>-</font>height<font face='Lucida Console'>)</font>
                    Q.<font color='#BB00BB'>pop_front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                out[rr<font color='#5555FF'>-</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>][cc] <font color='#5555FF'>+</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>Q.<font color='#BB00BB'>front</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.second, thresh<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_SPATIAL_FILTERINg_H_
</font>


</pre></body></html>